# -*- coding: utf-8 -*-
"""
Created on Sun Jun 28 14:45:28 2020

@author: Lenovo
"""
file_name = input("请输入你要查询的文件夹：  ")
com=[1,2,31,32,41,42,5,6,7,8,9,101,102,11,12,131,132,141,142,15,16]
# com=[1,2,31,32]
list_2=[]
import csv
for m in com:       
    f = open(file_name+'/'+str(m)+'.csv','r',encoding='UTF-8')
    reader=csv.reader(f)
    list_1 = []
    list_f=list(reader)[2:-1][::-1]
    for num in list_f:
        list_1.append(float(num[1]))
    if m != 16:
        n=0
        l2=[]
        while n < len(list_1)+1:
            if n % 3 == 0 and n > 2:
                l = []
                l.append(list_1[n-3])
                l.append(list_1[n-2])
                l.append(list_1[n-1])
                s=round(sum(l)/1000,3)
                l2.append(s)
            n+=1
        if m not in [32,42,102,132,142]:
            list_2.append(l2)
        else:
            n = 0
            for N in l2:
                list_2[-1][n]=list_2[-1][n]+l2[n]
                n+=1
    else:
        l2=[]
        for n_16 in list_1:
            l2.append(round((n_16*2.98/1000),3))  
        list_2.append(l2)
list_E=[]
m=len(list_2[0])
n=0
while n < m:
    for list_F in list_2:
        list_E.append(list_F[n:n+96])
    list_E.append([])
    n+=96
f1=open(file_name+'数据采集.csv','w',newline='')
writer=csv.writer(f1)
writer.writerows(list_E) #若不加[]，数字会被作为字符串一个一个写入表格
f1.close()
print("haole ")
     
